﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#chtt
    /// </summary>
    public class TitleParam : IRenderable
    {
        /// <summary>
        /// The name of the API
        /// </summary>
        public string Name { get { return "chtt"; } }


        /// <summary>
        /// The title of the chart
        /// </summary>
        public string Text { get; set; }


        /// <summary>
        /// The default constructor
        /// </summary>
        public TitleParam() { }


        /// <summary>
        /// The only constructor in town
        /// </summary>
        /// <param name="title"></param>
        public TitleParam(string title)
        {
            Text = title;
        }

        /// <summary>
        /// Render the chart parameter
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            // Bail if title is not set.
            if (String.IsNullOrEmpty(Text))
                return String.Empty;

            return String.Format("&{0}={1}", Name, Text.Replace(' ', '+').Replace("\n", "|"));
        }
    }
}
